-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First implementation of PDF viewer feature #138
Conversation
|
Codecov Report
@@ Coverage Diff @@
## master #138 +/- ##
==========================================
+ Coverage 24.83% 24.84% +<.01%
==========================================
Files 88 88
Lines 7493 7442 -51
==========================================
- Hits 1861 1849 -12
+ Misses 5632 5593 -39
Continue to review full report at Codecov.
|
- Fixed swiftlint warnings - Added missing removal of block-based notification observer and made the block hold self as weak reference, so it can't cause a retain cycle
self.contentView.addSubview(pageLabel) | ||
|
||
titleLabel.font = UIFont.systemFont(ofSize: titleFontSize, weight: UIFont.Weight.regular) | ||
titleLabel.adjustsFontSizeToFitWidth = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is already set to false. see adjustFontSizeToFitWidth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu yes, this line can be removed. The intention was to make the code more explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu fixed
return | ||
} | ||
DispatchQueue.main.async { | ||
if let cell : PDFThumbnailCollectionViewCell = self.collectionView?.cellForItem(at: indexPath) as? PDFThumbnailCollectionViewCell { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this in multiple places and it's only my preference of styling things, but you can chain if let
and avoid a los of { }
Something like:
if let cell : PDFThumbnailCollectionViewCell = self.collectionView?.cellForItem(at: indexPath) as? PDFThumbnailCollectionViewCell,
let visibleCells = self.collectionView?.visibleCells,
visibleCells.contains(cell) {
cell.imageView?.image = thumbnailImage
cell.pageLabel?.text = page.label
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu yes, true. I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu I checked once again, here chaining would sacrifice readability and in fact I only found one single other piece of code where chaining could have been applied.
fileprivate let ANIMATION_DUR = 0.25 | ||
fileprivate let THUMBNAIL_VIEW_WIDTH_MULTIPLIER: CGFloat = 0.15 | ||
fileprivate let THUMBNAIL_VIEW_HEIGHT_MULTIPLIER: CGFloat = 0.1 | ||
fileprivate let FILENAME_CONTAINER_TOP_MARGIN: CGFloat = 10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen that in some places you code constants in different styles, is there some reason to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu for me it was not clear if we have any official coding conventions and I didn't find an example of constants in existing code. What is the preferred style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, we don't have any rule defined for this neither any complete style guide apart of what we have in the SwiftLint file.
I think we can discuss the style guide in the new opened issue here #139
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu fixed
I found a couple of glitches worth fixing before diving into code review:
The background has the correct color after switching to the the icon view and back.
|
@felix-schwarz Regarding your comment:
I was thinking that we might add more icons in the navigation bar and therefore introduced an overlay but forgot to remove the file name from navigation bar. |
Which fixes glitch nr. 2 mentioned by @fschwarz
To avoid visual glitch
- Theming support - Thumbnail layout
…tion # Conflicts: # ownCloud.xcodeproj/project.pbxproj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the visual glitches and kudos to a really solid user experience! 👍
I made a few comments but from my perspective, this could also get merged as-is and the issues raised be addressed in a feature/pdfRefinements
branch.
With regards to the icons, it'd be good to keep track of who made them and how they are licensed. Did you draw them yourself in the scope of this project, or use third-party ones?
|
||
guard let currentPageLabel = pdfView.currentPage?.label else { return } | ||
|
||
pageCountLabel.text = "\(currentPageLabel) of \(pdf.pageCount)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ownCloud Manual.pdf
has "wild" page labels, so I get to see:
- "1 of 79" on the first page
- "i of 79" on the third page
- "1 of 79" on the fifth page
- "75 of 79" on the last page
I'd like to suggest:
- using
PDFDocument.index(for: page)
for this label - using
PDFPage.label
only in the table of contents - localizing the string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felix-schwarz good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felix-schwarz however.. I think there is a problem with your suggestion to use PDFDocument.index(for: page)
since it returns 0-based index.. so if page numbers start with something like i, ii, iii, 1, this method would return value 3 for page labeled "1".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mneuwert Good point! The first page should be page 1 of course :) … since the y
element of the "x of y" text is using the page count, the x
should be the page offset (+1) instead of the label to stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felix-schwarz There is still an issue, see ownCloud Manual.pdf
: sequence of page label in this document is:
1, 2, i, ii, 1, 2, 3 etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mneuwert I think for this "[page] of [total]" box at the bottom, PDF page labels are meaningless and prone to be inconsistent and confusing. Let's go for PDFDocument.index(for: page) + 1
.
ownCloud/Resources/Assets.xcassets/ic_pdf_view_continuous.imageset/Contents.json
Outdated
Show resolved
Hide resolved
fileprivate let pdfView = PDFView() | ||
fileprivate let thumbnailView = PDFThumbnailView() | ||
|
||
fileprivate let containerView = UIStackView() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a UIStackView
and putting the PDFView
into it will make it hard/impossible to show PDF content "underneath" elements above and below the pdf view like in Apple's Books.
Switching to a UIView
for the containerView would make that possible and generally give more room to the content.
self.contentView.addSubview(imageView!) | ||
|
||
pageLabel = UILabel() | ||
pageLabel?.backgroundColor = UIColor.clear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Page labels are difficult to read if the page is darker. As far as I can see, Apple Books uses a white (or bright gray?) color here so the page number remains legible even on dark backdrops. Getting that "label" look of Apple Books, though, may require another container view around the label.
@felix-schwarz Regarding icons, I used Google Material icons in PDF which use Apache v2 style license if I remember correctly. Link to Material icons which also references license: |
And the search UI is being dismissed, when user taps “Cancel”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes. The only thing I'd still like to see changed is using the page offset (+1) instead of the page label, which should be a very minor change. The rest is better dealt with in a refinement branch.
Approved! :-)
Not using page label but rather index of the current page + 1
Very good job @mneuwert!!. I have noticed a couple of things:
The only way to reestablish original page size after zooming in/out is repainting (change orientation or page up/down). Double tap should do that |
@jesmrec Fixed an issue with separator. Looks like zooming with double-tap is broken, when |
Approved |
Description
PDF viewer shall be implemented allowing comfortable viewing of PDF files.
Related Issue
#87
Motivation and Context
We would like to utilise PDFKit features to provide user experience similar to iBooks app while browsing PDF files.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: